﻿package cn.rayyee.utils
{
	
	/**
	 * ...
	 * @author 
	 */
	public class TimeFormat 
	{
		
		public static function getToTime(seconds:int, type:int):String
		{
			seconds = Number(seconds);
			var hours:Number = Math.floor(seconds / 3600);
			seconds = seconds - hours * 3600;
			var minutes:Number = Math.floor(seconds / 60);
			seconds = seconds - minutes * 60;
			if (!type) 
			{
				type = 1;
			}
			//返回的值      
			var return_info:String = "";
			//---------     1     ----------
			if (type == 1) 
			{
				return_info = (hours < 10) ? ("0" + hours) : hours.toString();
				return_info = return_info+":"+((minutes<10) ? ("0"+minutes) : minutes);
				return_info = return_info+":"+((seconds<10) ? ("0"+seconds) : seconds);
				return return_info;
			}
			//---------     2     ----------   
			if (type == 2) 
			{
				if (hours>0) {
					return_info = ((hours<10) ? ("0"+hours) : hours)+":";
				}
				if (minutes>0) {
					return_info = return_info+((minutes<10) ? ("0"+minutes) : minutes)+":";
				}
				return_info = return_info+((seconds<10) ? ("0"+seconds) : seconds);
				while ((return_info.charAt(0)) == "0") {
					return_info = return_info.slice(1);
				}
				return return_info;
			}
			//---------     3     ----------   
			if (type == 3)
			{
				if (hours>0) {
					return_info = ((hours<10) ? ("0"+hours) : hours)+":";
				}
				return_info = return_info+((minutes<10) ? ("0"+minutes) : minutes)+":";
				return_info = return_info+((seconds<10) ? ("0"+seconds) : seconds);
				while ((return_info.charAt(0)) == "0") {
					return_info = return_info.slice(1);
				}
				return return_info;
			}
			//---------     4     ----------   
			if (type == 4) 
			{
				return_info = (hours<10) ? ("0"+hours) : hours.toString();
				return_info = return_info+"时"+((minutes<10) ? ("0"+minutes) : minutes.toString());
				return_info = return_info+"分"+((seconds<10) ? ("0"+seconds) : seconds)+"秒";
				return return_info;
			}
			//---------     5     ----------   
			if (type == 5)
			{
				if (hours > 0) 
				{
					return_info = ((hours<10) ? ("0"+hours) : hours)+"时";
				}
				if (minutes > 0) 
				{
					return_info = return_info+((minutes<10) ? ("0"+minutes) : minutes)+"分";
				}
				return_info = return_info+((seconds<10) ? ("0"+seconds) : seconds)+"秒";
				while ((return_info.charAt(0)) == "0") 
				{
					return_info = return_info.slice(1);
				}
				return return_info;
			}
			//---------     6     ----------   
			if (type == 6)
			{
				if (hours > 0) 
				{
					return_info = ((hours<10) ? ("0"+hours) : hours)+"时";
				}
				return_info = return_info+((minutes<10) ? ("0"+minutes) : minutes)+"分";
				return_info = return_info+((seconds<10) ? ("0"+seconds) : seconds)+"秒";
				while ((return_info.charAt(0)) == "0") 
				{
					return_info = return_info.slice(1);
				}
				return return_info;
			}
			
			return return_info;
		}	
		
	}
	
}